<?php
/** 
 * Copyright (C) 2009 João Neto
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * @version viewhtml - 19/07/2009 - joaoneto
 */
defined('_JEXEC') or die( 'Restricted access' ); //no direct access

jimport( 'joomla.application.component.view');

class CategoryViewCategory extends JLoja_View
{
	var $_title = 'Categories';
	
	public function display( $tpl = null )
	{
		$this->assignRef( 'table', $this->_getTable() );
		JToolBarHelper::addNew( 'add' );
		parent::display( $tpl );
	}
	
	private function _getTable()
	{
		$categoryTree = $this->categories;
		$table = new JLoja_Html_Table( array( 'class' => 'adminlist', 'id' => 'adminForm', 'style' => 'width: 100%' ) );

		$head = new JLoja_Html_Table_Header();

		$head->addColumn( 'name', 'Name', array( 'class' => 'tt', 'sort' => 0 ) );
		$head->addColumn( 'name', 'Order', array( 'class' => 'tt', 'sort' => 0 ) );
		$head->addColumn( 'name', 'Published', array( 'class' => 'tt', 'sort' => 0 ) );
		$head->addColumn( 'name', 'Created Date', array( 'class' => 'tt', 'sort' => 0 ) );
		$head->addColumn( 'name', 'Id', array( 'class' => 'tt', 'sort' => 0 ) );

		$table->setHeader( $head );

		JLoja_Html_Debug::add( $categoryTree );
		foreach( $categoryTree->fetchAll() as $obj ){
			$levelSpc = str_repeat( '&nbsp&nbsp&nbsp&nbsp', $obj->level );
			$column = new JLoja_Html_Table_Row();
			$link = new JLoja_Html_Link( $obj->Translation[ JLoja_Lang::getCurrentLang() ]->nm_category, JRoute::_( 'index.php?option=com_jloja&controller=category&task=add&cid[]=' . $obj->id_category ) );
			$column->addColumn( 'name', $levelSpc . '<sup>|__</sup>' . $link, array( 'class' => 'tt', 'function' => 'load' ) );
			$column->addColumn( 'name', $obj->level, array( 'class' => 'tt', 'function' => 'load' ) );
			$column->addColumn( 'name', $obj->bo_published, array( 'class' => 'tt', 'function' => 'load' ) );
			$column->addColumn( 'name', $obj->dt_category_created, array( 'class' => 'tt', 'function' => 'load' ) );
			$column->addColumn( 'name', $obj->id_category, array( 'class' => 'tt', 'function' => 'load' ) );

			$table->addRow( $column );
		}

		return $table;
	}
}